package com.son.dao;

import com.son.domin.Student;
import com.son.domin.Teacher;

import java.util.ArrayList;

public class TeacherDaoImpl implements InterTeacherDao{

    public static ArrayList<Teacher> list=new ArrayList<>();
    static {
        Teacher teacher = new Teacher("001","张三","23","1999-11-11");
        Teacher teacher1 = new Teacher("002","李四","25","1995-11-11");
        Teacher teacher2 = new Teacher("003","王五","21","2000-11-11");
        list.add(teacher);
        list.add(teacher1);
        list.add(teacher2);
    }
    @Override
    public void addTeacher(Teacher teacher) {
        list.add(teacher);
    }

    @Override
    public int getIndex(String sid) {
        for (int i = 0; i < list.size(); i++) {
            Teacher teacher = list.get(i);
            if (teacher!=null&&teacher.getSid().equals(sid)){
                return i;
            }
        }
        return -1;
    }


    @Override
    public void deleteTeacher(String sid) {
        int index = getIndex(sid);
        list.remove(index);
    }

    @Override
    public void updateTeacher(String sid, Teacher teacher) {
        int index = getIndex(sid);
        list.set(index,teacher);
    }

    @Override
    public ArrayList<Teacher> findAllTeacher() {
        return list;
    }
}
